-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(metadata): properly handle casting non-numeric values in search operations with custom metadata #55184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
/backport to stable32 |
/backport to stable31 |
…perations with custom metadata If a metadata property is declared with a number type but the value provided are not numeric, it logs "A non-numeric value encountered at nextcloud/apps/dav/lib/Files/FileSearchBackend.php#486" instead of throwing a proper error. Now with a proper error we have the proper exception being thrown: InvalidArgumentException Invalid property value for {http://nextcloud.org/ns}metadata-photos-original_date_time Signed-off-by: Thomas Citharel <[email protected]>
96beacb
to
974cfef
Compare
if (is_numeric($value)) { | ||
return 0 + $value; | ||
} | ||
throw new \Error('Value for numeric datatype is not numeric'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if throwing in error is better or simply ignoring it with: return 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning was indeed that it allows for the throw new \InvalidArgumentException('Invalid property value for ' . $property->name, previous: $e);
exception to be thrown, so that the front-end can know something's wrong. Otherwise I might not have found about nextcloud/photos#3187
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this:
throw new \InvalidArgumentException(
sprintf(
'Invalid property value for %s: got "%s" (type: %s)',
$property->name,
is_scalar($value) ? (string)$value : gettype($value),
gettype($value)
)
);
and got 2 errors:
InvalidArgumentException Invalid property value for {http://owncloud.org/ns}size: got "0" (type: string)
InvalidArgumentException Invalid property value for {http://nextcloud.org/ns}metadata-photos-original_date_time: got "2024-10-09T00:00:00Z" (type: string)
I'm not sure if these errors can be safely ignored. If these warnings are not important, I'd prefer they not show up in the log.
If a metadata property is declared with a number type but the value provided are not numeric, it just logs "A non-numeric value encountered at
apps/dav/lib/Files/FileSearchBackend.php#486
" instead of throwing a proper error.Now with a proper error here we have the proper exception being thrown later:
InvalidArgumentException Invalid property value for {http://nextcloud.org/ns}metadata-photos-original_date_time
.See nextcloud/photos#3187 for the actual issue in photos.
(I'm too lazy to add a specific test for this, but feel free to)
Checklist